import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import { getURLParamByKey } from '@/util'

import 'lib-flexible/flexible.js'

import 'vant/lib/index.css'
import './assets/css/base.less'
import './assets/css/theme-reset.less'
import './assets/css/temp.less'

import {
  Toast,
  ActionSheet,
  Button,
  Form,
  Field,
  Uploader,
  Swipe,
  SwipeItem,
  Tab,
  Tabs,
  RadioGroup,
  Radio,
  Icon,
  List,
  Checkbox,
  Popup,
  Cascader,
  Picker,
  Search,
  Progress,
  Switch,
  Skeleton,
  DatetimePicker,
  Dialog,
  Popover,
  Calendar,
  PasswordInput,
  NumberKeyboard,
  NoticeBar,
  PullRefresh,
  Sticky,
  Lazyload,
  DropdownMenu,
  DropdownItem,
} from 'vant'
import { Image as VanImage } from 'vant'
// Toast，Dialog，Notify 和 ImagePreview 组件。在使用函数组件时，unplugin-vue-components 无法自动引入对应的样式，因此需要手动引入样式。
import 'vant/es/toast/style'
import 'vant/es/dialog/style'
import 'vant/es/notify/style'
import 'vant/es/image-preview/style'

const pinia = createPinia()
const app = createApp(App)

// async function loader() {
//   await new Promise(resolve => {
//     if (getURLParamByKey('token') || getURLParamByKey(process.env.VUE_APP_TOKEN_NAME)) {
//       localStorage.setItem(process.env.VUE_APP_TOKEN_NAME, getURLParamByKey(process.env.VUE_APP_TOKEN_NAME) || getURLParamByKey('token'))
//       resolve()
//     } else {
//       resolve()
//     }
//   })
// }
// loader()

app
  .use(Lazyload)
  .use(Toast)
  .use(ActionSheet)
  .use(Popover)
  .use(Button)
  .use(Form)
  .use(Dialog)
  .use(Field)
  .use(Uploader)
  .use(Swipe)
  .use(SwipeItem)
  .use(Tab)
  .use(Tabs)
  .use(Radio)
  .use(RadioGroup)
  .use(Icon)
  .use(List)
  .use(Checkbox)
  .use(Popup)
  .use(Cascader)
  .use(Picker)
  .use(Search)
  .use(Progress)
  .use(Switch)
  .use(Skeleton)
  .use(VanImage)
  .use(DatetimePicker)
  .use(Calendar)
  .use(PasswordInput)
  .use(NumberKeyboard)
  .use(NoticeBar)
  .use(PullRefresh)
  .use(Sticky)
  .use(DropdownMenu)
  .use(DropdownItem)
  .use(router)
  .use(pinia)
  .mount('#app')
